<template>
  <div class="rank">
    <heads />
     <van-loading size="24px" vertical  v-if="datas.length<2">加载中...</van-loading>
    <div class="item-box" v-for="(item, index) in datas" :key="index + 'love2'">
      <div class="ccc" >
        <div class="top"  v-if="item[1].length==5">
          <h3>{{ item[0]}}</h3>
          <router-link class="link" tag="div" to="/rank/rankList"
            >更多</router-link
          >
        </div> 
        <div class="item" v-if="item[1].length==5">
          <div class="fist" @click="goBook(item[1][0].id, item[1][0].title)">
            <div class="img">
              <img
                :src="item[1][0].cover"
                alt=""
                width="100"
                height="100%"
              />
            </div>
            <div class="txt">
              <div class="title">{{ item[1][0].title }}</div>
              <div class="at-bq">
                {{ item[1][0].author }}/{{ item[1][0].category }}
              </div>
              <div class="center">
                {{ item[1][0].content }}
              </div>
            </div>
          </div>
          <ul>
            <li  @click="goBook(item[1][1].id, item[1][1].title)">2 {{ item[1][1].title }}</li>
            <li  @click="goBook(item[1][2].id, item[1][2].title)">3 {{ item[1][2].title}}</li>
            <li  @click="goBook(item[1][3].id, item[1][3].title)">4 {{ item[1][3].title }}</li>
            <li  @click="goBook(item[1][4].id, item[1][4].title)">5 {{ item[1][4].title }}</li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import heads from "../components/heads.vue";
import { getList, getBook } from "../api/rank";
export default {
  components: { heads },
  data() {
    return {
      List: null,
      datas: [],
      flg:false
    };
  },
  methods:{
     goBook(id, name) {
      console.log(id, name);
      this.$router.push({
        path: "/bookDetails",
        query: { id: id, name: name },
      });
    },
  },
  watch: {
    List() {
      
      this.List.forEach((item) => {
        item.subNavis.forEach((i) => {
          // console.log(i.naviInfos[0].name);
          getBook(i.naviInfos[0].url).then((data) => {
            // console.log(data.list.splice(0, 5));
            if (data.list.splice(0, 5).length==5) {
              this.datas.push([i.naviInfos[0].name,data.list.splice(0, 5)]);
              console.log(this.datas);
            }
          });
        });
      });
    },
  },
  created() {
    getList().then((data) => {
      console.log(data);
      this.List = data.data.list;
    });
  },
  beforeRouteEnter(to, from, next){
    next();
  }
};
</script>

<style lang="less">
.rank {
  overflow: hidden;
  .item-box {
    padding: 15px;
    // border-bottom: 1px solid #ccc;
    background-color: #fff;
    .top {
      display: flex;
      align-items: center;
      justify-content: space-between;
      height: 28px;
      line-height: 28px;
      margin-bottom: 17px;
      .link {
        padding: 0 17px;
        font-size: 13px;
        font-weight: normal;
        color: #999;
        border: 1px solid #eeb5b5;
        border-radius: 28px;
      }
    }
    .item {
      border-bottom: 1px solid #ccc;
      .fist {
        display: flex;
        .img {
          width: 100px;
          height: 142px;
          margin-right: 10px;
          background-color: pink;
          flex-shrink: 0;
        }
        .txt {
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          .title {
            font-weight: normal;
            font-size: 16px;
            color: #3b352d;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
          .at-bq {
            font-size: 12px;
            color: #aba59a;
          }
          .center {
            display: -webkit-box;
            overflow: hidden;
            text-overflow: ellipsis;
            -webkit-line-clamp: 4;
            -webkit-box-orient: vertical;
            font-size: 14px;
            color: #807a73;
            overflow: hidden;
          }
        }
      }
      ul {
        margin-top: 17px;
        li {
          color: #6c6358;
          height: 18px;
          line-height: 18px;
          padding-bottom: 17px;
          font-size: 15px;
        }
      }
    }
  }
}
</style>